
package sr.codemg.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sr.codemg.entity.SysRoleMenu;
import sr.codemg.service.SysRoleMenuService;
import sr.codemg.vm.Base;
import sr.codemg.vm.Selects;
import sr.codemg.vm.SysRoleMenuData;
import sr.codemg.vm.Tables;

import java.util.Map;

/**
 * 权限菜单信息
 **/
@Slf4j
@RestController
@RequestMapping("/sysrolemenu")
public class SysRoleMenuController {

    @Autowired
    SysRoleMenuService sysRoleMenuService;

    @GetMapping("/{id}")
    public SysRoleMenu get(@PathVariable("id") String id) {
        String[] ids = new String[2];
        if (id.contains("&")) {
            ids = id.split("&");
        }

        return sysRoleMenuService.get(ids[0], ids[1]);
    }

    @PutMapping
    public Tables list(@RequestBody Map<String, Object> params) {
        return sysRoleMenuService.findList(params);
    }

    @PostMapping
    public Base.Response post(@RequestBody SysRoleMenu entity) {
        return sysRoleMenuService.add(entity);
    }

    @PutMapping("/edit")
    public Base.Response put(@RequestBody SysRoleMenuData entity) {
        return sysRoleMenuService.update(entity);
    }

    @DeleteMapping("/{roleId}")
    public Base.Response delete(@PathVariable("roleId") String roleId) {
        return sysRoleMenuService.delete(roleId);
    }

    @PostMapping("/select")
    public Selects.Response select(@RequestBody Selects.Request req) {
        return sysRoleMenuService.select(req);
    }
}

